<template>
  <el-row class="areaContent" :gutter="20">
    <el-col v-for="item in data" :key="item.id" class="item" :span="6">
      <el-tooltip effect="dark" :content="item.name" placement="top-start">
        <div
          class="content"
          :style="{backgroundColor:isImgUrl(item.topContent)?'#f8f8f8':'#fff'}"
          @click="handClickContent({item, status: 'sibarClick'})"
        >
          <div v-if="isImgUrl(item.icon)" class="top">{{ item.topContent }}</div>
          <div v-else class="top">
            <img src="@/assets/img/menu_icon.png" />
          </div>
          <div class="bottom">{{ item.name }}</div>
        </div>
      </el-tooltip>
    </el-col>
  </el-row>
</template>

<script>
import { getPath } from "@/util/avue.js";
import { mapGetters, mapMutations } from "vuex";
export default {
  name: "Item",
  props: {
    data: {
      type: Array,
      default: () => []
    },
    column: {
      type: [String, Number],
      default: 3
    }
  },
  computed: {
    ...mapGetters(["project"]),
    cItemStyle () {
      return {
        width: (100 / this.column) + "%"
      };
    }
  },
  methods: {
    ...mapMutations(["SET_IS_SHOW_PRJ", "SET_SIBAR_STATUS"]),
    isImgUrl (f) {
      if (f === null) {
        return false;
      }
      return !/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(f);
    },
    handRouter (item) {
      this.$router.push({
        path: getPath({
          name: item.name,
          src: item.path
        }),
        query: item.query
      });
    },
    handClickContent ({ item, status }) {
      this.SET_SIBAR_STATUS({ item, status });
      if (item.needProject === "1" && !this.project.projectName) {
        this.SET_IS_SHOW_PRJ(true);
      } else {
        if (item.pageMode === "3") {
          window.open(item.path);
        } else {
          this.handRouter(item);
        }
      }

    }
  },
  data () {
    return {
      key: Math.random()
    };
  },
  mounted () {
    this.key = Math.random();
  }
};
</script>

<style lang="less" scoped>
/deep/ .el-scrollbar__wrap {
  overflow-x: hidden !important;
}
.areaContent {
  width: 100%;
  display: flex;
  height: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
  // min-height: 200px;
  /deep/ .el-col {
    padding-left: 0 !important;
    // padding-right: 0 !important;
    // &:nth-child(3n) {
    //   padding-right: 0 !important;
    // }
  }
  flex-direction: row;
  flex-wrap: wrap;
  .item {
    height: 90px;
    margin-bottom: 5px;
    .content {
      // background: #f8f8f8;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      .top {
        margin-bottom: 13px;
        font-size: 36px;
        color: #ffac39;
        padding-top: 5px;
        // img {
        //   width: 42px;
        //   height: 34px;
        // }
      }
      .bottom {
        font-size: 14px;
        color: #666666;
        margin-bottom: 10px;
        width: 100%;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}
</style>